home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / fuzzyborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  4.5 KB  |  167 lines

  1. ;
  2. ; fuzzy-border
  3. ;
  4. ; Do a cool fade to a given colour at the border of an image (optional shadow)
  5. ; Will make image RGB if it isn't already.
  6. ;
  7. ; Chris Gutteridge (cjg@ecs.soton.ac.uk)
  8. ; At ECS Dept, University of Southampton, England.
  9.  
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ; GNU General Public License for more details.
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. ; Define the function:
  23.  
  24. (define (script-fu-fuzzy-border    inImage
  25.                 inLayer
  26.                 inColor
  27.                 inSize
  28.                 inBlur
  29.                 inGranu
  30.                 inShadow
  31.                 inShadWeight
  32.                 inCopy
  33.                                 inFlatten
  34.     )
  35.          
  36.     (gimp-selection-all inImage)
  37.     (set! theImage (if (= inCopy TRUE)
  38.                (car (gimp-image-duplicate inImage))
  39.                        inImage)
  40.         )
  41.     (if     (>     (car (gimp-drawable-type inLayer))
  42.                        1
  43.                 )
  44.         (gimp-image-convert-rgb theImage)
  45.     )
  46.         (set! theWidth (car (gimp-image-width inImage)))
  47.     (set! theHeight (car (gimp-image-height inImage)))
  48.  
  49.     (set! theLayer (car (gimp-layer-new     theImage
  50.                         theWidth
  51.                         theHeight
  52.                         RGBA-IMAGE
  53.                         "layer 1"
  54.                         100
  55.                         NORMAL-MODE
  56.     ) ) )
  57.  
  58.     (gimp-image-add-layer theImage theLayer 0)
  59.  
  60.  
  61.         (gimp-edit-clear theLayer)
  62.     (chris-color-edge theImage theLayer inColor inSize)
  63.  
  64.     (gimp-layer-scale     theLayer
  65.                 (/ theWidth inGranu)
  66.                 (/ theHeight inGranu)
  67.                 TRUE
  68.     )
  69.  
  70.     (plug-in-spread     TRUE
  71.                 theImage
  72.                 theLayer
  73.                 (/ inSize inGranu)
  74.                 (/ inSize inGranu)
  75.     )
  76.     (chris-color-edge theImage theLayer inColor 1)
  77.     (gimp-layer-scale theLayer theWidth theHeight TRUE)
  78.     
  79.     (gimp-selection-layer-alpha theLayer)
  80.     (gimp-selection-invert theImage)
  81.     (gimp-edit-clear theLayer)
  82.     (gimp-selection-invert theImage)
  83.     (gimp-edit-clear theLayer)
  84.     (gimp-context-set-background inColor)
  85.     (gimp-edit-fill theLayer BACKGROUND-FILL)
  86.         (gimp-selection-none inImage)
  87.     (chris-color-edge theImage theLayer inColor 1)
  88.         
  89.     (if     (= inBlur TRUE)
  90.         (plug-in-gauss-rle TRUE theImage theLayer inSize TRUE TRUE)
  91.         ()
  92.     )
  93.     (if (= inShadow FALSE)
  94.         ()
  95.             (begin
  96.                 (gimp-selection-none inImage)
  97.             (gimp-image-add-layer     theImage
  98.                      (car (gimp-layer-copy     theLayer
  99.                                 FALSE
  100.                     ))
  101.                     0
  102.             )
  103.         (gimp-layer-scale     theLayer (- theWidth inSize) (- theHeight inSize) TRUE)
  104.             (gimp-desaturate theLayer)
  105.         (gimp-brightness-contrast theLayer 127 127)
  106.             (gimp-invert theLayer)
  107.         (gimp-layer-resize     theLayer
  108.                        theWidth
  109.                         theHeight
  110.                         (/ inSize 2)
  111.                         (/ inSize 2)
  112.         )
  113.         (plug-in-gauss-rle     TRUE
  114.                         theImage
  115.                         theLayer
  116.                         (/ inSize 2)
  117.                         TRUE
  118.                         TRUE
  119.         )
  120.         (gimp-layer-set-opacity theLayer inShadWeight)
  121.             )
  122.     )
  123.     (if     (= inFlatten TRUE)
  124.          (gimp-image-flatten theImage)
  125.         ()
  126.     )
  127.     (if     (= inCopy TRUE)
  128.         (begin     (gimp-image-clean-all theImage)
  129.             (gimp-display-new theImage)
  130.         )
  131.         ()
  132.     )
  133.     (gimp-displays-flush)
  134. )
  135.  
  136. (define (chris-color-edge inImage inLayer inColor inSize)
  137.           (gimp-selection-all inImage)
  138.           (gimp-selection-shrink inImage inSize)
  139.           (gimp-selection-invert inImage)
  140.       (gimp-context-set-background inColor)
  141.     (gimp-edit-fill theLayer BACKGROUND-FILL)
  142.           (gimp-selection-none inImage)
  143. )
  144.  
  145. (script-fu-register "script-fu-fuzzy-border"
  146.             _"_Fuzzy Border..."
  147.             "Fade border to chosen color"
  148.             "Chris Gutteridge"
  149.             "1998, Chris Gutteridge / ECS dept, University of Southampton, England."
  150.             "3rd April 1998"
  151.             "RGB* GRAY*"
  152.             SF-IMAGE       "The image"              0
  153.             SF-DRAWABLE    "The layer"              0
  154.             SF-COLOR      _"Color"                  '(255 255 255)
  155.             SF-ADJUSTMENT _"Border size"            '(16 1 300 1 10 0 1)
  156.             SF-TOGGLE     _"Blur border"            TRUE
  157.             SF-ADJUSTMENT _"Granularity (1 is Low)" '(4 1 16 0.25 5 2 0)
  158.             SF-TOGGLE     _"Add shadow"             FALSE
  159.             SF-ADJUSTMENT _"Shadow weight (%)"      '(100 0 100 1 10 0 0)
  160.             SF-TOGGLE     _"Work on copy"           TRUE
  161.             SF-TOGGLE     _"Flatten image"          TRUE)
  162.  
  163. (script-fu-menu-register "script-fu-fuzzy-border"
  164.              _"<Image>/Script-Fu/Decor")
  165.